
var myScroll,
	pullDownEl, pullDownOffset,
	pullUpEl, pullUpOffset,
	generatedCount = 0;
    var pp=1,nomore=false;
function pullDownAction () {
	console.log(1111);
	setTimeout(function () {	// <-- Simulate network congestion, remove setTimeout from production!
		 localStorage.removeItem('indexid');
		 var aa=window.location.href;
		 if(aa.indexOf('index.html')>0){
		 	 window.location='index.html';
		 }else{
		 	if(aa.indexOf('searche.html')>0){

		 	}else{
		 		location.reload();
		 	}

		 }
		myScroll.refresh();		// Remember to refresh when contents are loaded (ie: on ajax completion)
	}, 1000);	// <-- Simulate network congestion, remove setTimeout from production!
}

//function pullUpAction () {
//	setTimeout(function () {	// <-- Simulate network congestion, remove setTimeout from production!
//		var el, li, i;
//
//
//		for (i=0; i<13; i++) {
//			console.log(i);
//		}
//
//		myScroll.refresh();		// Remember to refresh when contents are loaded (ie: on ajax completion)
//	}, 1000);	// <-- Simulate network congestion, remove setTimeout from production!
//}

function loaded() {
	pullDownEl = document.getElementById('pullDown');
	pullDownOffset = pullDownEl.offsetHeight;
	pullUpEl = document.getElementById('pullUp');
	pullUpOffset = pullUpEl.offsetHeight;

	myScroll = new iScroll('wrapper', {
		useTransition: true,
		click:true,
		momentum: true,
	    preventDefaultException: { tagName:  /^(INPUT|TEXTAREA|BUTTON|SELECT)$/ },
		topOffset: pullDownOffset,
		onScrollStart:function(){
			$('#wrapper').trigger('scroll');
		},
		onRefresh: function () {
			if (pullDownEl.className.match('loading')) {
				pullDownEl.className = '';
				pullDownEl.querySelector('.pullDownLabel').innerHTML = '下拉刷新页面';
			} else if (pullUpEl.className.match('loading')) {
				pullUpEl.className = '';
				pullUpEl.querySelector('.pullUpLabel').innerHTML = '';
			}
			$('#wrapper').trigger('scroll');
		},
		onScrollMove: function () {
			if (this.y > 5 && !pullDownEl.className.match('flip')) {
				pullDownEl.className = 'flip';
				pullDownEl.querySelector('.pullDownLabel').innerHTML = '下拉刷新页面';
				this.minScrollY = 0;
				setTimeout(function () {	// <-- Simulate network congestion, remove setTimeout from production!
		 localStorage.removeItem('indexid');
		 var aa=window.location.href;
		 if(aa.indexOf('index.html')>0){
		 	 window.location='index.html';
		 }else{

		 	if(aa.indexOf('searche.html')>0){

		 	}else{
		 		location.reload();
		 	}
		 }
		myScroll.refresh();		// Remember to refresh when contents are loaded (ie: on ajax completion)
	}, 1000);
			} else if (this.y < 5 && pullDownEl.className.match('flip') ) {
				pullDownEl.className = '';
				pullDownEl.querySelector('.pullDownLabel').innerHTML = '下拉刷新页面';
				this.minScrollY = -pullDownOffset;
			} else if (this.y < (this.maxScrollY - 6) && !pullUpEl.className.match('flip') && !nomore) {
				pullUpEl.className = 'flip';
				pullUpEl.querySelector('.pullUpLabel').innerHTML = '上拉加载更多';
				this.maxScrollY = this.maxScrollY;
			} else if (this.y > (this.maxScrollY + 6) && pullUpEl.className.match('flip') && !nomore) {
				pullUpEl.className = '';
				pullUpEl.querySelector('.pullUpLabel').innerHTML = '上拉加载更多';
				this.maxScrollY = pullUpOffset;
			}
			$('#wrapper').trigger('scroll');
		},
		onScrollEnd: function () {
		   var aa=$('img.lazy:last').attr('data-original');
                  $('img.lazy:last').attr('src',aa);
			if (pullDownEl.className.match('flip') && !nomore) {
				pullDownEl.className = 'loading';
				pullDownEl.querySelector('.pullDownLabel').innerHTML = '下拉刷新页面';
				pullDownAction();	// Execute custom function (ajax call?)
			} else if (pullUpEl.className.match('flip') && !nomore) {
				pullUpEl.className = 'loading';
				pullUpEl.querySelector('.pullUpLabel').innerHTML = '加载数据';
				pullUpAction();	// Execute custom function (ajax call?)
			}

			$('#wrapper').trigger('scroll');
		}
	});

	setTimeout(function () { document.getElementById('wrapper').style.left = '0'; }, 800);
}

document.addEventListener('touchmove', function (e) { e.preventDefault(); }, false);

document.addEventListener('DOMContentLoaded', function () { setTimeout(loaded, 200); }, false);